home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 101-125 / scopedisk118 / cosmicquest / conquest.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  38KB  |  1,308 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <fcntl.h>
  4. #include "defs.h"
  5. #include "ships.h"
  6.  
  7. extern long Revision;
  8. extern struct NStar star[STARNO];
  9. extern struct NTask task[PLAYERNO][TASKNO+1];
  10. extern struct NCommData CommData[PLAYERNO];
  11. extern struct NGeneral general;
  12. extern int growth[PLANETNO];
  13. extern struct NShip ship[SHIPNO];
  14.  
  15.  
  16. extern int fline;
  17. extern int mode,mode2,mode3;
  18. extern int file;
  19. extern int waittime;
  20.  
  21. conquest()
  22.   {
  23.   int pla,sta,x,y;
  24.   char *year="Year 0000";
  25.   init();
  26.   do
  27.     {
  28.     general.time++;
  29.     qstr(general.time,year+5);
  30.     cprint(PLAYERNO,"COSMIC CONQUEST",year,"Please wait","while fighting","");
  31.     for(sta=0;sta<STARNO;sta++)
  32.       {
  33.       update(sta);
  34.       if(fight(sta))
  35.         cprint(PLAYERNO,"COSMIC CONQUEST",year,"Please wait","while fighting","");
  36.       }
  37.     for(pla=0;pla<PLAYERNO;pla++)
  38.       {
  39.       cprint(PLAYERNO,"COSMIC CONQUEST",year,"It is the turn of",general.pname[pla],"");
  40.       wait_space(pla);
  41.       if(comp_cmp("klingon",general.pname[pla])) klingon(pla);
  42.       else 
  43.       if(comp_cmp("romulan",general.pname[pla])) romulan(pla);
  44.       else 
  45.       if(comp_cmp("alien",general.pname[pla])) alien(pla);
  46.       else 
  47.       if(comp_cmp("berserker",general.pname[pla])) berserker(pla);
  48.       else if(!comp_cmp("dead",general.pname[pla])) human(pla);
  49.       if (mode3)
  50.         {
  51.         x=mode2;mode2=0;y=mode3;mode3=0;
  52.         if (!display_check(pla) && exists(pla))
  53.           {
  54.           mode2=x;mode3=y;
  55.           human(pla);
  56.           }
  57.         else
  58.           {
  59.           mode2=x;
  60.           mode3=y;
  61.           }
  62.         }
  63.       clean_task(pla);
  64.       clearall(pla);
  65.       }
  66.     cprint(PLAYERNO,"COSMIC CONQUEST",year,"Please wait","while processing turn","");
  67.     process_turn();
  68.     }
  69.   while(playon());
  70.   deinit();
  71.   }
  72. load(str)
  73. char *str;
  74.   {
  75.   int pla,sta,tas;
  76.   char fname[STRLENGTH+10];
  77.   if(*str=='\0') cleanup("Bad filename");
  78.   strcpy(fname,"games/");
  79.   strcat(fname,str);
  80.   file=open(fname,O_RDONLY);
  81.   if(file==-1) return(0);
  82.   read(file,&general,sizeof(struct NGeneral));
  83.   for(sta=0;sta<STARNO;sta++) read(file,&star[sta],sizeof(struct NStar));
  84.   for(pla=0;pla<PLAYERNO;pla++)
  85.     for(tas=0;tas<TASKNO;tas++)
  86.       read(file,&task[pla][tas],sizeof(struct NTask));
  87.   for(pla=0;pla<PLAYERNO;pla++)
  88.     read(file,&CommData[pla],sizeof(struct NCommData));
  89.   close(file);file=-1;
  90.   return(1);
  91.   }
  92. save(str)
  93. char *str;
  94.   {
  95.   int pla,sta,tas;
  96.   char fname[STRLENGTH+10];
  97.   if(*str=='\0') cleanup("Bad filename");
  98.   strcpy(fname,"games/");
  99.   strcat(fname,str);
  100.   file=open(fname,O_WRONLY|O_CREAT);
  101.   if(file==-1) return(0);
  102.   write(file,&general,sizeof(struct NGeneral));
  103.   for(sta=0;sta<STARNO;sta++) write(file,&star[sta],sizeof(struct NStar));
  104.   for(pla=0;pla<PLAYERNO;pla++)
  105.     for(tas=0;tas<TASKNO;tas++)
  106.       write(file,&task[pla][tas],sizeof(struct NTask));
  107.   for(pla=0;pla<PLAYERNO;pla++)
  108.     write(file,&CommData[pla],sizeof(struct NCommData));
  109.   close(file);file=-1;
  110.   return(1);
  111.   }
  112. init()
  113.   {
  114.   int i,j,k,c;
  115.   char filename[STRLENGTH];
  116.   char *version="V1.0000";
  117.   version[6]='0'+Revision%10;
  118.   version[5]='0'+(Revision/10)%10;
  119.   version[4]='0'+(Revision/100)%10;
  120.   version[3]='0'+(Revision/1000)%10;
  121.   cprint(PLAYERNO,"COSMIC CONQUEST",version,"Placed in the PD","by Carl Edman","");
  122.   wait_space(PLAYERNO);
  123.   randomize();
  124.   cprint(PLAYERNO,"COSMIC CONQUEST","","Do you wish to ...","1.Start a new game  ","2.Restore an old one");
  125.   while((c=coget())<'1' || c>'2');
  126.   if(c=='1')
  127.     {
  128.     cprint(PLAYERNO,"COSMIC CONQUEST","","Please enter name of players","","");
  129.     for(i=0;i<PLAYERNO;i++)
  130.       {
  131.       cinput(general.pname[i],3);
  132.       for(j=0;j<i;j++) if(!strcmp(general.pname[j],general.pname[i])) break;
  133.       if (j<i || strlen(general.pname[i])==0) 
  134.         {
  135.         nprint(PLAYERNO,"Invalid name.");
  136.         i--;
  137.         }
  138.       else nprint(PLAYERNO,"OK.");
  139.       }
  140.     cprint(PLAYERNO,"COSMIC CONQUEST","","Please wait while","creating the galaxy","");
  141.     for(i=0;i<STARNO;i++) for(j=0;j<PLANETNO;j++)
  142.       {
  143.       star[i].planet[j].ruler=PLAYERNO;
  144.       star[i].planet[j].size=0;
  145.       star[i].planet[j].population=0;
  146.       star[i].planet[j].poptype=PLAYERNO;
  147.       star[i].planet[j].industry=0;
  148.       star[i].planet[j].producing=DO_NOTHING;
  149.       star[i].planet[j].ipoints=0;
  150.       star[i].planet[j].mineable=0;
  151.       }
  152.     for(i=0;i<(11*PLANETNO*STARNO)/100;i++) star[RANDOM(STARNO)].planet[RANDOM(PLANETNO)].size=10;
  153.     for(i=0;i<( 9*PLANETNO*STARNO)/100;i++) star[RANDOM(STARNO)].planet[RANDOM(PLANETNO)].size=20;
  154.     for(i=0;i<( 7*PLANETNO*STARNO)/100;i++) star[RANDOM(STARNO)].planet[RANDOM(PLANETNO)].size=40;
  155.     for(i=0;i<( 4*PLANETNO*STARNO)/100;i++) star[RANDOM(STARNO)].planet[RANDOM(PLANETNO)].size=60;
  156.     for(i=0;i<( 3*PLANETNO*STARNO)/100;i++) star[RANDOM(STARNO)].planet[RANDOM(PLANETNO)].size=120;
  157.     for(i=0;i<(10*PLANETNO*STARNO)/100;i++) star[RANDOM(STARNO)].planet[RANDOM(PLANETNO)].mineable=1;
  158.     spread_stars();
  159.     while(spread_players()) spread_stars();
  160.     for(i=0;i<PLAYERNO;i++)
  161.       {
  162.       general.techlevel[i]=100;
  163.       for(j=0;j<PLAYERNO;j++) general.relation[i][j]=PEACE;
  164.       for(j=1;j<=TASKNO;j++)
  165.         {
  166.         task[i][j].headed=-1;
  167.         task[i][j].arriving=0;
  168.         for(k=0;k<SHIPNO;k++)
  169.           {
  170.           task[i][j].ship_free[k]=0;
  171.           task[i][j].ship_load[k]=0;
  172.           }
  173.         }
  174.       for(j=0;j<STARNO;j++)
  175.         {
  176.         CommData[i].star[j].ruler=PLAYERNO;
  177.         CommData[i].star[j].totsize=0;
  178.         CommData[i].star[j].totpop=0;
  179.         CommData[i].star[j].totind=0;
  180.         CommData[i].star[j].danger=100;
  181.         CommData[i].star[j].when=-1000;
  182.         }
  183.       if(comp_cmp("dead",general.pname[i]))
  184.         {
  185.         task[i][0].headed=-1;
  186.         continue;
  187.         }
  188.       star[task[i][0].headed].planet[3].size=60;
  189.       star[task[i][0].headed].planet[3].mineable=1;
  190.       star[task[i][0].headed].planet[3].population=60;
  191.       star[task[i][0].headed].planet[3].poptype=i;
  192.       star[task[i][0].headed].planet[3].industry=60;
  193.       star[task[i][0].headed].planet[3].ruler=i;
  194.       star[task[i][0].headed].planet[3].producing=MINING;
  195.       star[task[i][0].headed].planet[4].size=40;
  196.       star[task[i][0].headed].planet[4].mineable=0;
  197.       task[i][0].headed=-1;
  198.       }
  199.     general.time=0;
  200.     }
  201.   else
  202.     {
  203.     cprint(PLAYERNO,"COSMIC CONQUEST","","Please enter name of game","","");
  204.     cinput(filename,3);
  205.     while(!load(filename))
  206.       {
  207.       nprint(PLAYERNO,"Error loading file.");
  208.       cinput(filename,3);
  209.       }
  210.     }
  211.   clearall(PLAYERNO);
  212.   }
  213. deinit()
  214.   {
  215.   int c;
  216.   char *version="V1.0000";
  217.   version[6]='0'+Revision%10;
  218.   version[5]='0'+(Revision/10)%10;
  219.   version[4]='0'+(Revision/100)%10;
  220.   version[3]='0'+(Revision/1000)%10;
  221.   cprint(PLAYERNO,"COSMIC CONQUEST",version,"by Carl Edman","(C) 1988","GOODBYE !");
  222.   wait_space(PLAYERNO);
  223.   }
  224. task_speed(pla,tas)
  225. int pla;
  226. int tas;
  227.   {
  228.   int shi,k=10000;
  229.   for(shi=0;shi<SHIPNO;shi++) if(task[pla][tas].ship_free[shi]) k=MIN(k,ship[shi].hypspeed);
  230.   return(k);
  231.   }
  232. task_range(pla,tas)
  233. int pla;
  234. int tas;
  235.   {
  236.   int shi,k=10000;
  237.   for(shi=0;shi<SHIPNO;shi++) if(task[pla][tas].ship_free[shi]) k=MIN(k,ship[shi].hyprange);
  238.   return(k);
  239.   }
  240. task_capa(pla,tas)
  241. int pla;
  242. int tas;
  243.   {
  244.   int shi,k=0;
  245.   for(shi=0;shi<SHIPNO;shi++)
  246.     k+=INTASK(pla,tas,shi)*ship[shi].capacity;
  247.   return(k);
  248.   }
  249. task_visi(pla,tas)
  250. int pla;
  251. int tas;
  252.   {
  253.   int shi,k=0;
  254.   for(shi=0;shi<SHIPNO;shi++)
  255.     k+=task[pla][tas].ship_free[shi]*ship[shi].capacity;
  256.   return(k);
  257.   }
  258. task_free(pla,tas)
  259. int pla;
  260. int tas;
  261.   {
  262.   int shi,k=0;
  263.   for(shi=0;shi<SHIPNO;shi++)
  264.     k+=task[pla][tas].ship_load[shi]*ship[shi].size;
  265.   return(task_capa(pla,tas)-k);
  266.   }
  267. task_size(pla,tas)
  268. int pla;
  269. int tas;
  270.   {
  271.   int shi,k=0;
  272.   for(shi=0;shi<SHIPNO;shi++)
  273.     k+=task[pla][tas].ship_free[shi]*ship[shi].size;
  274.   return(k);
  275.   }
  276. task_size_po(pla,tas)
  277. int pla;
  278. int tas;
  279.   {
  280.   int shi,k=0;
  281.   for(shi=0;shi<SHIPNO-2;shi++)
  282.     k+=task[pla][tas].ship_free[shi]*ship[shi].size;
  283.   return(k);
  284.   }
  285. knowstar(pla,sta)
  286. int pla;
  287. int sta;
  288.   {
  289.   int p;
  290.   if (mode==pla) return(1);
  291.   for(p=0;p<PLANETNO;p++)
  292.     if(star[sta].planet[p].ruler==pla || star[sta].planet[p].poptype==pla) return(1);
  293.   if(search_task(pla,sta)!=TASKNO) return(1);else return(0);
  294.   }
  295. headedstar(pla,sta)
  296. int pla;
  297. int sta;
  298.   {
  299.   int tas;
  300.   for(tas=0;tas<TASKNO;tas++) if(task[pla][tas].headed==sta) return(1);
  301.   return(0);
  302.   }
  303. controlstar(sta)
  304. int sta;
  305.   {
  306.   int p,pla;
  307.   for(p=0;p<PLANETNO;p++) if(star[sta].planet[p].ruler!=PLAYERNO) break;
  308.   if (p==PLANETNO) return(UNINHABITED);
  309.   pla=star[sta].planet[p].ruler;
  310.   for(p++;p<PLANETNO;p++) if(star[sta].planet[p].ruler!=PLAYERNO && star[sta].planet[p].ruler!=pla) break;
  311.   if(p!=PLANETNO) return(FIGHTING);
  312.   return(pla);
  313.   }
  314. rule_star(pl1,pl2)
  315. int pl1;
  316. int pl2;
  317.   {
  318.   int sta,p;
  319.   for(sta=0;sta<STARNO;sta++)
  320.     for(p=0;p<PLANETNO;p++) if(star[sta].planet[p].ruler==pl1 && star[sta].planet[p].poptype==pl2) return(1);
  321.   return(0);
  322.   }
  323. search_task(pla,sta)
  324. int pla;
  325. int sta;
  326.   {
  327.   int tas;
  328.   for(tas=0;tas<TASKNO;tas++) if(ATSTAR(pla,tas,sta)) return(tas);
  329.   return(TASKNO);
  330.   }
  331. clean_task(pla)
  332. int pla;
  333.   {
  334.   int tas,shi;
  335.   for(tas=0;tas<TASKNO;tas++)
  336.     {
  337.     if (task[pla][tas].headed==-1) continue;
  338.     for(shi=0;shi<SHIPNO;shi++)
  339.       if(task[pla][tas].ship_free[shi] || task[pla][tas].ship_load[shi]) break;
  340.     if(shi==SHIPNO)
  341.       {
  342.       task[pla][tas].headed=-1;
  343.       continue;
  344.       }
  345.     while(task_free(pla,tas)<0)
  346.       for(shi=0;shi<SHIPNO;shi++)
  347.         if(task[pla][tas].ship_load[shi]>0)
  348.           {
  349.           task[pla][tas].ship_load[shi]--;
  350.           task[pla][tas].ship_free[shi]++;
  351.           break;
  352.           }
  353.     }
  354.   }
  355. process_turn()
  356.   {
  357.   int sta,tas,p,gr,pla,pro;
  358.   for(sta=0;sta<STARNO;sta++) for(p=0;p<PLANETNO;p++) if(star[sta].planet[p].size)
  359.     {
  360.     if(star[sta].planet[p].population==0 || star[sta].planet[p].ruler==PLAYERNO)
  361.       {
  362.       star[sta].planet[p].poptype=PLAYERNO;
  363.       star[sta].planet[p].population=0;
  364.       star[sta].planet[p].industry=0;
  365.       star[sta].planet[p].ruler=PLAYERNO;
  366.       star[sta].planet[p].producing=DO_NOTHING;
  367.       continue;
  368.       }
  369.     pla=star[sta].planet[p].ruler;
  370.     pro=star[sta].planet[p].producing;
  371.     gr=growth[p]-(4*star[sta].planet[p].population/star[sta].planet[p].size);
  372.     if(gr<0) gr=0;
  373.     gr *= (int)star[sta].planet[p].population;
  374.     if(RANDOM(100)<gr%100)
  375.       star[sta].planet[p].population+= gr/100+1;
  376.     else
  377.       star[sta].planet[p].population+= gr/100;
  378.     if(star[sta].planet[p].population>star[sta].planet[p].size)
  379.       {
  380.       if(star[sta].planet[p].poptype==pla)
  381.         {
  382.         tas=get_task(pla,sta);
  383.         if(tas!=-1)
  384.           set_ships_free(pla,tas,POPUNIT,
  385.                        (((int) star[sta].planet[p].population)-star[sta].planet[p].size)
  386.                        +task[pla][tas].ship_free[POPUNIT]);
  387.         }
  388.       star[sta].planet[p].population=star[sta].planet[p].size;
  389.       }
  390.     if(star[sta].planet[p].industry>star[sta].planet[p].population) star[sta].planet[p].industry=star[sta].planet[p].population;
  391.     star[sta].planet[p].ipoints += star[sta].planet[p].industry;
  392.     switch(pro)
  393.       {
  394.       case INVESTING:
  395.           star[sta].planet[p].industry+=star[sta].planet[p].ipoints/ICOST;
  396.           star[sta].planet[p].ipoints %= ICOST;
  397.           break;
  398.       case RESEARCHING:
  399.           general.techlevel[pla]+=(star[sta].planet[p].ipoints/RCOST)/(general.techlevel[pla]/100);
  400.           star[sta].planet[p].ipoints %= RCOST*(general.techlevel[pla]/100);
  401.           break;
  402.       case MINING:
  403.           tas=get_task(pla,sta);
  404.           if(tas!=-1)
  405.           set_ships_free(pla,tas,OREUNIT,
  406.                          ((int) task[pla][tas].ship_free[OREUNIT])+star[sta].planet[p].ipoints/MCOST);
  407.           star[sta].planet[p].ipoints %= MCOST;
  408.           break;
  409.       case DO_NOTHING:
  410.           star[sta].planet[p].ipoints=0;
  411.           break;
  412.       default:
  413.           tas=get_task(pla,sta);
  414.           if(tas!=-1)
  415.           set_ships_free(pla,tas,pro,
  416.                          ((int) task[pla][tas].ship_free[pro]) 
  417.                          +star[sta].planet[p].ipoints/ship[pro].techcost);
  418.           star[sta].planet[p].ipoints %= ship[pro].techcost;
  419.           break;
  420.       }
  421.     if(star[sta].planet[p].industry<5) star[sta].planet[p].industry++;
  422.     if(star[sta].planet[p].industry>star[sta].planet[p].population) star[sta].planet[p].industry=star[sta].planet[p].population;
  423.     }
  424.   }
  425. get_task(pla,sta)
  426. int pla;
  427. int sta;
  428.   {
  429.   int tas;
  430.   tas=search_task(pla,sta);
  431.   if (tas<TASKNO) return(tas);
  432.   return(make_task(pla,sta));
  433.   }
  434. make_task(pla,sta)
  435. int pla;
  436. int sta;
  437.   {
  438.   int tas,shi;
  439.   for(tas=0;tas<TASKNO;tas++) if(task[pla][tas].headed==-1) break;
  440.   if (tas==TASKNO) return(-1);
  441.   task[pla][tas].headed=sta;
  442.   task[pla][tas].arriving=general.time;
  443.   for(shi=0;shi<SHIPNO;shi++)
  444.     task[pla][tas].ship_free[shi]=task[pla][tas].ship_load[shi]=0;
  445.   return(tas);
  446.   }
  447. playon()
  448.   {
  449.   int c;
  450.   int p,pla,pla2;
  451.   char filename[STRLENGTH];
  452.   if (waittime>general.time) return(1);
  453.   for(pla=0;pla<PLAYERNO;pla++) if(exists(pla)) break;
  454.   if (pla==PLAYERNO)
  455.     {
  456.     cprint(PLAYERNO,"COSMIC CONQUEST","GAME OVER","","No survivors","");
  457.     wait_space(PLAYERNO);
  458.     return(0);
  459.     }
  460.   for(pla2=pla+1;pla2<PLAYERNO;pla2++) if(exists(pla2)) break;
  461.   if(pla2==PLAYERNO)
  462.     {
  463.     cprint(PLAYERNO,"COSMIC CONQUEST","GAME OVER",general.pname[pla],"has won the galaxy","");
  464.     wait_space(PLAYERNO);
  465.     return(0);
  466.     }
  467.   cprint(PLAYERNO,"COSMIC CONQUEST","","Do you wish to ...","1.Save Game","2.Don't save");
  468.   while((c=coget())<'1' || c>'2') ;
  469.   if(c=='1')
  470.     {
  471.     cprint(PLAYERNO,"COSMIC CONQUEST","","Please enter name of game","","");
  472.     cinput(filename,3);
  473.     while(!save(filename))
  474.       {
  475.       cinput(filename,3);
  476.       nprint(PLAYERNO,"Error saving file.");
  477.       }
  478.     }
  479.   cprint(PLAYERNO,"COSMIC CONQUEST","","Do you wish to ...","1.Quit","2.Play on");
  480.   while((c=coget())<'1' || c>'2') ;
  481.   return(c=='2');
  482.   }
  483. distance(sta1,sta2)
  484. int sta1;
  485. int sta2;
  486.   {
  487.   int r,q;
  488.   if(sta1<0 || sta1>=STARNO || sta2<0 || sta2>=STARNO) return(1000);
  489.   q =(star[sta1].x-star[sta2].x)*(star[sta1].x-star[sta2].x);
  490.   q+=(star[sta1].y-star[sta2].y)*(star[sta1].y-star[sta2].y);
  491.   for(r=0;r*r<q;r++);
  492.   return(r);
  493.   }
  494. do_command(pla,co)
  495. int pla;
  496. struct NCommand *co;
  497.   {
  498.   int i,j,k,l,sta,tas;
  499.   int c0,c1,c2,c3;
  500.   c0=co->par[0];
  501.   c1=co->par[1];
  502.   c2=co->par[2];
  503.   c3=co->par[3];
  504.   switch(co->com)
  505.     {
  506.     case DUMMY: /* DUMMY   */
  507.       if (mode2) printf("Pla %d:DUMMY\n",pla);
  508.       return(0);
  509.     case LAND:/* [0]=task [1]=planet */
  510.       if (mode2) printf("Pla %d:LAND Task %d Planet %d\n",pla,c0,c1);
  511.       if(task[pla][c0].headed==-1)
  512.         {
  513.         nprint(pla,"No such taskforce.");
  514.         return(-1);
  515.         }
  516.       if(task[pla][c0].arriving>general.time)
  517.         {
  518.         nprint(pla,"Taskforce in hyperspace.");
  519.         return(-1);
  520.         }
  521.       i=task[pla][c0].headed;
  522.       c2=MIN(INTASK(pla,c0,POPUNIT),star[i].planet[c1].size-star[i].planet[c1].population);
  523.       c3=MIN(INTASK(pla,c0,OREUNIT),star[i].planet[c1].population+c2-star[i].planet[c1].industry);
  524.       if(star[i].planet[c1].size==0)
  525.         {
  526.         nprint(pla,"No such planet.");
  527.         return(-1);
  528.         }
  529.       if(star[i].planet[c1].ruler!=pla && star[i].planet[c1].ruler!=PLAYERNO && c2>0)
  530.         {
  531.         nprint(pla,"Planet under alien control.");
  532.         return(-1);
  533.         }
  534.       if(star[i].planet[c1].poptype!=pla && star[i].planet[c1].population>0 && star[i].planet[c1].poptype!=PLAYERNO && c2>0)
  535.         {
  536.         nprint(pla,"Alien population on planet.");
  537.         return(-1);
  538.         }
  539.       if(star[i].planet[c1].ruler!=pla && c2==0 && c3>0)
  540.         {
  541.         nprint(pla,"Planet not under control.");
  542.         return(-1);
  543.         }
  544.       if(star[i].planet[c1].population+c2==0 && c3>0)
  545.         {
  546.         nprint(pla,"No colony on planet.");
  547.         return(-1);
  548.         }
  549.       if(c2>0)
  550.         {
  551.         star[i].planet[c1].ruler=pla;
  552.         star[i].planet[c1].poptype=pla;
  553.         }
  554.       star[i].planet[c1].population += c2;
  555.       c2 = task[pla][c0].ship_free[POPUNIT]-c2;
  556.       set_ships_free(pla,c0,POPUNIT,c2);
  557.       if(c2<0)
  558.         set_ships_load(pla,c0,POPUNIT,((int) task[pla][c0].ship_load[POPUNIT])+c2);
  559.       star[i].planet[c1].industry += c3;
  560.       c3 = task[pla][c0].ship_free[OREUNIT]-c3;
  561.       set_ships_free(pla,c0,OREUNIT,c3);
  562.       if(c3<0)
  563.         set_ships_load(pla,c0,OREUNIT,((int) task[pla][c0].ship_load[OREUNIT])+c3);
  564.       clean_task(pla);
  565.       update(i);
  566.       nprint(pla,"OK.");
  567.       return(1);
  568.     case CARRY:/* [0]=task [1]=ship of type 0........*/
  569.       if (mode2) printf("Pla %d:CARRY Task %d POPUNIT:%d OREUNIT:%d\n",pla,c0,co->par[POPUNIT+1],co->par[OREUNIT+1]);
  570.       if(task[pla][c0].headed==-1)
  571.         {
  572.         nprint(pla,"No such taskforce.");
  573.         return(-1);
  574.         }
  575.       if(task[pla][c0].arriving>general.time)
  576.         {
  577.         nprint(pla,"Taskforce in hyperspace.");
  578.         return(-1);
  579.         }
  580.       for(i=0;i<SHIPNO;i++) 
  581.         if (co->par[i+1]>INTASK(pla,c0,i))
  582.           break;
  583.       if(i!=SHIPNO)
  584.         {
  585.         nprint(pla,"Insufficient number of ships.");
  586.         return(-1);
  587.         }
  588.       for(i=0;i<SHIPNO;i++) if(co->par[i+1]!=task[pla][c0].ship_load[i]) break;
  589.       if(i==SHIPNO)
  590.         {
  591.         nprint(pla,"No change.");
  592.         return(1);
  593.         }
  594.       k=0;
  595.       for(i=0;i<SHIPNO;i++)
  596.         k+=INTASK(pla,c0,i)*ship[i].capacity-co->par[i+1]*ship[i].size;
  597.       if(k<0)
  598.         {
  599.         nprint(pla,"Insufficient capacity.");
  600.         return(-1);
  601.         }
  602.       for(i=0;i<SHIPNO;i++)
  603.         {
  604.         k=INTASK(pla,c0,i);
  605.         set_ships_load(pla,c0,i,co->par[i+1]);
  606.         set_ships_free(pla,c0,i,k-co->par[i+1]);
  607.         }
  608.       clean_task(pla);
  609.       nprint(pla,"OK.");
  610.       return(1);
  611.     case DESTINATION:/* [0]=task [1]=star */
  612.       if (mode2) printf("Pla %d:DESTINATION Task %d Star %d\n",pla,c0,c1);
  613.       if(task[pla][c0].headed==-1)
  614.         {
  615.         nprint(pla,"No such taskforce.");
  616.         return(-1);
  617.         }
  618.       if(task[pla][c0].arriving>general.time)
  619.         {
  620.         nprint(pla,"Taskforce in hyperspace.");
  621.         return(-1);
  622.         }
  623.       if(task[pla][c0].headed==c1)
  624.         {
  625.         nprint(pla,"Taskforce already at star.");
  626.         return(-1);
  627.         }
  628.       i=distance(task[pla][c0].headed,c1);
  629.       k=task_free(pla,c0);
  630.       for(j=0;j<SHIPNO;j++)
  631.         if(task[pla][c0].ship_free[j]>0 && ship[j].hyprange<i)
  632.           k-=task[pla][c0].ship_free[j]*ship[j].size;
  633.       if(k<0)
  634.         {
  635.         nprint(pla,"Distance to long.");
  636.         return(-1);
  637.         }
  638.       for(j=0;j<SHIPNO;j++) if(ship[j].hyprange<i)
  639.         {
  640.         set_ships_load(pla,c0,j,INTASK(pla,c0,j));
  641.         task[pla][c0].ship_free[j]=0;
  642.         }
  643.       k=task_free(pla,c0);
  644.       for(l=0;l<50;l++)
  645.         {
  646.         for(j=0;j<SHIPNO;j++) if(ship[j].hypspeed==l)
  647.           k -= task[pla][c0].ship_free[j]*ship[j].size;
  648.         if(k<0) break;
  649.         }
  650.       for(j=0;j<SHIPNO;j++) if(ship[j].hypspeed<l)
  651.         {
  652.         set_ships_load(pla,c0,j,INTASK(pla,c0,j));
  653.         task[pla][c0].ship_free[j]=0;
  654.         }
  655.       j=task_speed(pla,c0);
  656.       task[pla][c0].headed=c1;
  657.       task[pla][c0].arriving=general.time+ (i+j-1)/j;
  658.       nprint(pla,"OK.");
  659.       return(1);
  660.     case EMIGRATION:/* [0]=star [1]=planet [2]=amount */
  661.       if (mode2) printf("Pla %d:EMIGRATION Star %d Planet %d Amount %d\n",pla,c0,c1,c2);
  662.       if(star[c0].planet[c1].size==0)
  663.         {
  664.         nprint(pla,"No such planet.");
  665.         return(-1);
  666.         }
  667.       if(star[c0].planet[c1].ruler!=pla)
  668.         {
  669.         nprint(pla,"Planet not under control.");
  670.         return(-1);
  671.         }
  672.       if(star[c0].planet[c1].population==0)
  673.         {
  674.         nprint(pla,"Not inhabited.");
  675.         return(-1);
  676.         }
  677.       if(star[c0].planet[c1].poptype!=pla)
  678.         {
  679.         nprint(pla,"Alien population.");
  680.         return(-1);
  681.         }
  682.       if(star[c0].planet[c1].population<c2)
  683.         {
  684.         nprint(pla,"Population to small.");
  685.         return(-1);
  686.         }
  687.       i=get_task(pla,c0);
  688.       if(i==-1)
  689.         {
  690.         nprint(pla,"Too few Taskforces.");
  691.         return(-1);
  692.         }
  693.       set_ships_free(pla,i,POPUNIT,((int) task[pla][i].ship_free[POPUNIT])+c2);
  694.       star[c0].planet[c1].population -= c2;
  695.       if(star[c0].planet[c1].population==0)
  696.         {
  697.         star[c0].planet[c1].poptype=PLAYERNO;
  698.         star[c0].planet[c1].ruler=PLAYERNO;
  699.         }
  700.       if(star[c0].planet[c1].industry>star[c0].planet[c1].population)
  701.         star[c0].planet[c1].industry=star[c0].planet[c1].population;
  702.       update(c0);
  703.       nprint(pla,"OK.");
  704.       return(i);
  705.     case JOIN:/* [0]=task1 [1]=task2 ...*/
  706.       if (mode2) printf("Pla %d:JOIN Tasks %d %d %d %d\n",pla,c0,c1,c2,c3);
  707.       if(c0==TASKNO)
  708.         {
  709.         nprint(pla,"At least 1 taskforce to join.");
  710.         return(-1);
  711.         }
  712.       for(i=0;co->par[i]!=TASKNO;i++) if(task[pla][co->par[i]].headed==-1) break;
  713.       if(co->par[i]!=TASKNO)
  714.         {
  715.         nprint(pla,"No such taskforce.");
  716.         return(-1);
  717.         }
  718.       for(i=0;co->par[i]!=TASKNO;i++) if(task[pla][co->par[i]].arriving>general.time) break;
  719.       if(co->par[i]!=TASKNO)
  720.         {
  721.         nprint(pla,"Taskforce in hyperspace.");
  722.         return(-1);
  723.         }
  724.       j=task[pla][c0].headed;
  725.       for(i=0;co->par[i]!=TASKNO;i++) if(task[pla][co->par[i]].headed!=j) break;
  726.       if(co->par[i]!=TASKNO)
  727.         {
  728.         nprint(pla,"Taskforces not at same star.");
  729.         return(-1);
  730.         }
  731.       for(i=0;co->par[i]!=TASKNO;i++)
  732.         {
  733.         for(j=0;;j++) if(co->par[j]==TASKNO || (j!=i && co->par[i]==co->par[j])) break;
  734.         if(co->par[j]!=TASKNO) break;
  735.         }
  736.       if(co->par[i]!=TASKNO)
  737.         {
  738.         nprint(pla,"Can't selfjoin taskforce.");
  739.         return(-1);
  740.         }
  741.       for(i=1;co->par[i]!=TASKNO;i++)
  742.         {
  743.         for(j=0;j<SHIPNO;j++)
  744.           {
  745.           set_ships_free(pla,c0,j,((int) task[pla][c0].ship_free[j])+task[pla][co->par[i]].ship_free[j]);
  746.           set_ships_load(pla,c0,j,((int) task[pla][c0].ship_load[j])+task[pla][co->par[i]].ship_load[j]);
  747.           }
  748.         task[pla][co->par[i]].headed=-1;
  749.         }
  750.       nprint(pla,"OK.");
  751.       return(1);
  752.     case KILL:/* [0]=star [1]=planet*/
  753.       if (mode2) printf("Pla %d:KILL Star %d Planet %d\n",pla,c0,c1);
  754.       if(c1==PLANETNO)
  755.         {
  756.         j=SHIPNO;
  757.         for(i=0;i<TASKNO && j==SHIPNO;i++)
  758.           if(ATSTAR(pla,i,c0))
  759.             for(j=0;j<SHIPNO;j++)
  760.               if((ship[j].special&STARKILLER)&&task[pla][i].ship_free[j]) break;
  761.         if(i==TASKNO && j==SHIPNO)
  762.           {
  763.           nprint(pla,"No starkiller unloaded.");
  764.           return(-1);
  765.           }
  766.         for(i=0;i<PLAYERNO;i++)
  767.           for(j=0;j<TASKNO;j++) if(ATSTAR(i,j,c0)) task[i][j].headed=-1;
  768.         for(i=0;i<PLANETNO;i++)
  769.           {
  770.           star[c0].planet[i].size=0;
  771.           star[c0].planet[i].poptype=PLAYERNO;
  772.           star[c0].planet[i].population=0;
  773.           star[c0].planet[i].industry=0;
  774.           star[c0].planet[i].ruler=PLAYERNO;
  775.           star[c0].planet[i].producing=DO_NOTHING;
  776.           }
  777.         update(c0);
  778.         return(1);
  779.         }
  780.       if(star[c0].planet[c1].size==0)
  781.         {
  782.         nprint(pla,"No such planet.");
  783.         return(-1);
  784.         }
  785.       if(star[c0].planet[c1].ruler!=pla)
  786.         {
  787.         nprint(pla,"Planet not under control.");
  788.         return(-1);
  789.         }
  790.       if(star[c0].planet[c1].population==0)
  791.         {
  792.         nprint(pla,"Not inhabited.");
  793.         return(-1);
  794.         }
  795.       if(star[c0].planet[c1].poptype==pla)
  796.         {
  797.         nprint(pla,"Own population.");
  798.         return(-1);
  799.         }
  800.       star[c0].planet[c1].poptype=PLAYERNO;
  801.       star[c0].planet[c1].population=0;
  802.       star[c0].planet[c1].industry=0;
  803.       star[c0].planet[c1].ruler=PLAYERNO;
  804.       star[c0].planet[c1].producing=DO_NOTHING;
  805.       update(c0);
  806.       nprint(pla,"OK.");
  807.       return(1);
  808.     case SPLIT:/* [0]=task [1]=ship of type 0........*/
  809.       if (mode2) printf("Pla %d:SPLIT Task %d POPUNITS %d OREUNITS %d\n",pla,c0,co->par[POPUNIT+1],co->par[OREUNIT+1]);
  810.       if(task[pla][c0].headed==-1)
  811.         {
  812.         nprint(pla,"No such taskforce.");
  813.         return(-1);
  814.         }
  815.       if(task[pla][c0].arriving>general.time)
  816.         {
  817.         nprint(pla,"Taskforce in hyperspace.");
  818.         return(-1);
  819.         }
  820.       for(i=0;i<SHIPNO;i++) 
  821.         if (co->par[i+1]>INTASK(pla,c0,i))
  822.           break;
  823.       if(i!=SHIPNO)
  824.         {
  825.         nprint(pla,"Insufficient number of ships.");
  826.         return(-1);
  827.         }
  828.       for(i=0;i<SHIPNO;i++) if(co->par[i+1]!=0) break;
  829.       if(i==SHIPNO)
  830.         {
  831.         nprint(pla,"New taskforce without ships.");
  832.         return(-1);
  833.         }
  834.       for(i=0;i<SHIPNO;i++) if(co->par[i+1]!=INTASK(pla,c0,i)) break;
  835.       if(i==SHIPNO)
  836.         {
  837.         nprint(pla,"Old taskforce without ships.");
  838.         return(c0);
  839.         }
  840.       j=make_task(pla,task[pla][c0].headed);
  841.       if(j==-1)
  842.         {
  843.         nprint(pla,"To few taskforces.");
  844.         return(-1);
  845.         }
  846.       for(i=0;i<SHIPNO;i++)
  847.         {
  848.         k = task[pla][c0].ship_free[i] + task[pla][c0].ship_load[i];
  849.         task[pla][j].ship_free[i]=co->par[i+1];
  850.         k -= task[pla][j].ship_free[i];
  851.         task[pla][c0].ship_free[i] = MIN(k,250);
  852.         k -= task[pla][c0].ship_free[i];
  853.         task[pla][c0].ship_load[i] = k;
  854.         }
  855.       tas=task[pla][c0].headed;
  856.       clean_task(pla);
  857.       nprint(pla,"OK.");
  858.       return(j);
  859.     case PRODUCE:/* [0]=star [1]=planet [2]=what */
  860.       if (mode2) printf("Pla %d:PRODUCE Star %d Planet %d Product %d\n",pla,c0,c1,c2);
  861.       if(star[c0].planet[c1].size==0)
  862.         {
  863.         nprint(pla,"No such planet.");
  864.         return(-1);
  865.         }
  866.       if(star[c0].planet[c1].ruler!=pla)
  867.         {
  868.         nprint(pla,"Planet not under control.");
  869.         return(-1);
  870.         }
  871.       if(star[c0].planet[c1].industry==0)
  872.         {
  873.         nprint(pla,"No production facilities.");
  874.         return(-1);
  875.         }
  876.       if(c2<SHIPNO && (ship[c2].special&NOTPROD))
  877.         {
  878.         nprint(pla,"Not producable.");
  879.         return(-1);
  880.         }
  881.       if(c2<SHIPNO && ship[c2].techlevel>general.techlevel[pla])
  882.         {
  883.         nprint(pla,"Techlevel too low.");
  884.         return(-1);
  885.         }
  886.       if(c2==MINING && !star[c0].planet[c1].mineable)
  887.         {
  888.         nprint(pla,"Planet not mineable.");
  889.         return(-1);
  890.         }
  891.       if(star[c0].planet[c1].producing!=c2)
  892.         star[sta].planet[c1].ipoints=MIN(star[sta].planet[c1].ipoints,star[sta].planet[c1].industry-1);
  893.       star[c0].planet[c1].producing=c2;
  894.       nprint(pla,"OK.");
  895.       return(1);
  896.     case DECLARE:/* [0]=on whom [1]=what */
  897.       if (mode2) printf("Pla %d:DECLARE DecPla %d Status %d\n",pla,c0,c1);
  898.       if(c0==pla)
  899.         {
  900.         nprint(pla,"Impossible.");
  901.         return(-1);
  902.         }
  903.       general.relation[pla][c0]=c1;
  904.       nprint(pla,"OK.");
  905.       return(1);
  906.     case POSSESS:/* [0]=star [1]=planet */
  907.       if (mode2) printf("Pla %d:POSSESS Star %d Planet %d\n",pla,c0,c1);
  908.       if(search_att_task(pla,c0)==TASKNO)
  909.         {
  910.         nprint(pla,"No fighting taskforce at star.");
  911.         return(-1);
  912.         }
  913.       if(star[c0].planet[c1].size==0)
  914.         {
  915.         nprint(pla,"No such planet.");
  916.         return(-1);
  917.         }
  918.       if(star[c0].planet[c1].ruler==pla)
  919.         {
  920.         nprint(pla,"Planet already controlled.");
  921.         return(-1);
  922.         }
  923.       if(star[c0].planet[c1].population==0)
  924.         {
  925.         nprint(pla,"Planet uninhabited.");
  926.         return(-1);
  927.         }
  928.       for(i=0;i<PLAYERNO;i++) if (i!=pla && general.relation[i][pla]!=ALLIANCE && search_att_task(i,c0)!=TASKNO) break;
  929.       if(i!=PLAYERNO)
  930.         {
  931.         nprint(pla,"Other powers present.");
  932.         return(-1);
  933.         }
  934.       if(general.techlevel[star[c0].planet[c1].ruler]>general.techlevel[pla])
  935.         general.techlevel[pla]+=MIN(general.techlevel[star[c0].planet[c1].ruler]-general.techlevel[pla],star[c0].planet[c1].industry/2);
  936.       star[c0].planet[c1].ruler=pla;
  937.       update(c0);
  938.       nprint(pla,"OK.");
  939.       return(1);
  940.     default   :;/*ERROR*/
  941.       if (mode2) printf("Pla %d:ERROR %d\n",pla,co->com);
  942.       return(-1);
  943.     }
  944.   }
  945. display_check(pla)
  946. int pla;
  947.   {
  948.   if(waittime>general.time) return(0);
  949.   if(pla==PLAYERNO || mode2 || mode3) return(1);
  950.   if(pla==-1) return(0);
  951.   if(comp_cmp("klingon",general.pname[pla])) return(0);
  952.   if(comp_cmp("romulan",general.pname[pla])) return(0);
  953.   if(comp_cmp("alien",general.pname[pla])) return(0);
  954.   if(comp_cmp("berserker",general.pname[pla])) return(0);
  955.   if(comp_cmp("dead",general.pname[pla])) return(0);
  956.   return(1);
  957.   }
  958. fight(sta)
  959. int sta;
  960.   {
  961.   int speed,tas,shi,pla1,pla2,i,j,disp;
  962.   char *c=" ";
  963.   for(pla1=0;pla1<PLAYERNO;pla1++)
  964.     {
  965.     if(search_att_task(pla1,sta)==TASKNO) continue;
  966.     for(pla2=0;pla2<PLAYERNO;pla2++)
  967.       if(search_task(pla2,sta)!=TASKNO && general.relation[pla1][pla2]==WAR) break;
  968.     if(pla2<PLAYERNO) break;
  969.     }
  970.   if(pla1==PLAYERNO) return(0);
  971.   for(pla2=0;pla2<PLAYERNO;pla2++)
  972.     {
  973.     if(!knowstar(pla2,sta)) continue;
  974.     if(display_check(pla2)) break;
  975.     }
  976.   if(pla2<PLAYERNO) disp=PLAYERNO;else disp=-1;
  977.   c[0]='A'+sta;
  978.   cprint(disp,"COSMIC CONQUEST","","Battle at Star",c,"");
  979.   starsummary(disp,sta);
  980.   for(pla1=0;pla1<PLAYERNO;pla1++)
  981.     {
  982.     task[pla1][TASKNO].headed=-1;
  983.     for(shi=0;shi<SHIPNO;shi++)
  984.       {
  985.       task[pla1][TASKNO].ship_free[shi]=0;
  986.       task[pla1][TASKNO].ship_load[shi]=0;
  987.       }
  988.     for(tas=0;tas<TASKNO;tas++)
  989.       if(ATSTAR(pla1,tas,sta))
  990.         {
  991.         for(shi=0;shi<SHIPNO;shi++)
  992.           {
  993.           set_ships_free(pla1,TASKNO,shi,((int) task[pla1][TASKNO].ship_free[shi])+task[pla1][tas].ship_free[shi]);
  994.           set_ships_load(pla1,TASKNO,shi,((int) task[pla1][TASKNO].ship_load[shi])+task[pla1][tas].ship_load[shi]);
  995.           } 
  996.         task[pla1][tas].headed=-1;
  997.         task[pla1][TASKNO].headed=sta;
  998.         task[pla1][TASKNO].arriving=0;
  999.         }
  1000.     i=0;
  1001.     for(shi=0;shi<SHIPNO;shi++) if(ship[shi].special&FASTEJECTER) i+=task[pla1][TASKNO].ship_free[shi]*ship[shi].capacity;
  1002.     for(shi=0;shi<SHIPNO && i>0;shi++)
  1003.       {
  1004.       j=0;
  1005.       if(ship[shi].special&FASTEJECTABLE) j=MIN(i/ship[shi].size,task[pla1][TASKNO].ship_load[shi]);
  1006.       set_ships_free(pla1,TASKNO,shi,task[pla1][TASKNO].ship_free[shi]+j);
  1007.       task[pla1][TASKNO].ship_load[shi] -= j;
  1008.       i -= j*ship[shi].size;
  1009.       }
  1010.     if (task[pla1][TASKNO].headed!=-1)
  1011.       {
  1012.       tasksummary(disp,pla1,TASKNO);
  1013.       wait_space(disp);
  1014.       }
  1015.     }
  1016.   fight_now(disp);
  1017.   for(pla1=0;pla1<PLAYERNO;pla1++)
  1018.     if(popore_task(pla1,TASKNO))
  1019.       {
  1020.       i=0;
  1021.       for(pla2=0;pla2<PLAYERNO;pla2++)
  1022.         if(att_task(pla2,TASKNO)&&general.relation[pla2][pla1]==WAR) i++;
  1023.       if(i==0) continue;
  1024.       i=INTASK(pla1,TASKNO,OREUNIT)/i;
  1025.       task[pla1][TASKNO].ship_free[POPUNIT]=task[pla1][TASKNO].ship_load[POPUNIT]=0;
  1026.       task[pla1][TASKNO].ship_free[OREUNIT]=task[pla1][TASKNO].ship_load[OREUNIT]=0;
  1027.       for(pla2=0;pla2<PLAYERNO;pla2++)
  1028.         if(att_task(pla2,TASKNO)&&general.relation[pla2][pla1]==WAR)
  1029.           set_ships_free(pla2,TASKNO,OREUNIT,task[pla2][TASKNO].ship_free[OREUNIT]+i);
  1030.       }
  1031.   for(pla1=0;pla1<PLAYERNO;pla1++)
  1032.     {
  1033.     tas=get_task(pla1,sta);
  1034.     if (tas==-1) continue;
  1035.     for(shi=0;shi<SHIPNO;shi++)
  1036.       {
  1037.       task[pla1][tas].ship_free[shi]=task[pla1][TASKNO].ship_free[shi];
  1038.       task[pla1][tas].ship_load[shi]=task[pla1][TASKNO].ship_load[shi];
  1039.       }
  1040.     clean_task(pla1);
  1041.     }
  1042.   wait_space(disp);
  1043.   clearall(disp);
  1044.   return(1);
  1045.   }
  1046. fight_now(disp)
  1047. int disp;
  1048.   {
  1049.   int cspeed,shi1,shi2,pla1,pla2,pla3,pl,x,ano,target,last;
  1050.   register int attack;
  1051.   int plashi[PLAYERNO];
  1052.   int platar[PLAYERNO];
  1053.   for(pla1=0;pla1<PLAYERNO;pla1++)
  1054.     {
  1055.     platar[pla1]=0;
  1056.     for(pla2=0;pla2<PLAYERNO;pla2++)
  1057.       if(general.relation[pla1][pla2]==WAR || general.relation[pla2][pla1]==WAR) platar[pla1]+=task_size_po(pla2,TASKNO);
  1058.     }
  1059.   for(cspeed=0;cspeed<MAXSPEED;cspeed++)
  1060.   for(shi1=0;shi1<SHIPNO;shi1++)
  1061.     {
  1062.     if(ship[shi1].attackno==0 || ship[shi1].speed!=cspeed) continue;
  1063.     pl=RANDOM(PLAYERNO);
  1064.     last=x;
  1065.     for(pla1=0;pla1<PLAYERNO;pla1++) plashi[pla1]=task[pla1][TASKNO].ship_free[shi1];
  1066.     for(x=pl;x<=last+PLAYERNO;x++)
  1067.       {
  1068.       pla1=x%PLAYERNO;
  1069.       if(plashi[pla1]!=0)
  1070.         {
  1071.         last=x;
  1072.         plashi[pla1]--;
  1073.         for(ano=0;ano<ship[shi1].attackno;ano++)
  1074.           {
  1075.           if(platar[pla1]<=0) continue;
  1076.           target=RANDOM(platar[pla1]);
  1077.           for(pla2=0;pla2<PLAYERNO;pla2++)
  1078.             {
  1079.             if(general.relation[pla1][pla2]!=WAR && general.relation[pla2][pla1]!=WAR) continue;
  1080.             for(shi2=0;shi2<SHIPNO-2;shi2++)
  1081.               {
  1082.               target -= task[pla2][TASKNO].ship_free[shi2]*ship[shi2].size;
  1083.               if(target<0) break;
  1084.               }
  1085.             if(shi2!=SHIPNO-2) break;
  1086.             }
  1087.           attack  = RSGN() * ship[shi1].attack;
  1088.           attack += RSGN() * ship[shi1].attack;
  1089.           attack += RSGN() * ship[shi1].attack;
  1090.           attack += RSGN() * ship[shi1].attack;
  1091.           attack = ship[shi1].attack+attack/4;
  1092.           if(attack<1)
  1093.             {
  1094.             output_fight(disp,pla1,shi1,pla2,shi2,"Miss");
  1095.             continue;
  1096.             }
  1097.           if(ship[shi2].shields>attack)
  1098.             {
  1099.             output_fight(disp,pla1,shi1,pla2,shi2,"Shields");
  1100.             continue;
  1101.             }
  1102.           output_fight(disp,pla1,shi1,pla2,shi2,"Destroyed");
  1103.           task[pla2][TASKNO].ship_free[shi2]--;
  1104.           if(ship[shi1].special&KAMIKAZE)
  1105.             {
  1106.             task[pla1][TASKNO].ship_free[shi1]--;
  1107.             for(pla3=0;pla3<PLAYERNO;pla3++)
  1108.               if(general.relation[pla3][pla1]==WAR || general.relation[pla1][pla3]==WAR) platar[pla3]-= ship[shi1].size;
  1109.             }
  1110.           for(pla3=0;pla3<PLAYERNO;pla3++)
  1111.             if(general.relation[pla3][pla2]==WAR || general.relation[pla2][pla3]==WAR) platar[pla3]-= ship[shi2].size;
  1112.           }
  1113.         }
  1114.       }
  1115.     }
  1116.   }
  1117. search_att_task(pla,sta)
  1118. int pla;
  1119. int sta;
  1120.   {
  1121.   int tas;
  1122.   for(tas=0;tas<TASKNO;tas++)
  1123.     if(ATSTAR(pla,tas,sta) && att_task(pla,tas)) return(tas);
  1124.   return(TASKNO);
  1125.   }
  1126. att_task(pla,tas)
  1127. int pla;
  1128. int tas;
  1129.   {
  1130.   int shi;
  1131.   if(task[pla][tas].headed==-1) return(0);
  1132.   for(shi=0;shi<SHIPNO-2;shi++) if(INTASK(pla,tas,shi) && ship[shi].attackno) return(1);
  1133.   return(0);
  1134.   }
  1135. popore_task(pla,tas)
  1136. int pla;
  1137. int tas;
  1138.   {
  1139.   int shi;
  1140.   for(shi=0;shi<SHIPNO-2;shi++) if(INTASK(pla,tas,shi)) return(0);
  1141.   return(1);
  1142.   }
  1143. exists(pla)
  1144. int pla;
  1145.   {
  1146.   int t,s,p;
  1147.   for(s=0;s<STARNO;s++) for(p=0;p<PLANETNO;p++)
  1148.     if(star[s].planet[p].poptype==pla && star[s].planet[p].ruler==pla && star[s].planet[p].population>0) return(1);
  1149.   for(t=0;t<TASKNO;t++) if(task[pla][t].headed!=-1 && INTASK(pla,t,POPUNIT)) return(1);
  1150.   return(0);
  1151.   }
  1152. population_no(pla)
  1153. int pla;
  1154.   {
  1155.   int i=0,s,p;
  1156.   for(s=0;s<STARNO;s++) for(p=0;p<PLANETNO;p++)
  1157.         if(star[s].planet[p].poptype==pla) i += star[s].planet[p].population;
  1158.   return(i);
  1159.   }
  1160. industry_no(pla)
  1161. int pla;
  1162.   {
  1163.   int i=0,s,p;
  1164.   for(s=0;s<STARNO;s++) for(p=0;p<PLANETNO;p++) 
  1165.     if(star[s].planet[p].ruler==pla) 
  1166.       i += star[s].planet[p].industry;
  1167.   return(i);
  1168.   }
  1169. nearstar(sta)
  1170. int sta;
  1171.   {
  1172.   int sta1=-1,dis,j;
  1173.   dis=1000;
  1174.   for(j=0;j<STARNO;j++) if(j!=sta && distance(sta,j)<dis) {sta1=j;dis=distance(sta,sta1);}
  1175.   return(sta1);
  1176.   }
  1177. set_ships_free(pla,tas,shi,no)
  1178. int pla;
  1179. int tas;
  1180. int shi;
  1181. int no;
  1182.   {
  1183.   if(no<0) no=0;
  1184.   if(no>250) no=250;
  1185.   task[pla][tas].ship_free[shi]=no;
  1186.   }
  1187. set_ships_load(pla,tas,shi,no)
  1188. int pla;
  1189. int tas;
  1190. int shi;
  1191. int no;
  1192.   {
  1193.   if(no<0) no=0;
  1194.   if(no>250) no=250;
  1195.   task[pla][tas].ship_load[shi]=(unsigned char) no;
  1196.   }
  1197. comp_cmp(name,str)
  1198. char *name;
  1199. char *str;
  1200.   {
  1201.   while(_tolower(*name)==_tolower(*str) && *name!='\0') {name++;str++;}
  1202.   if(*name=='\0') return(1);
  1203.   return(0);
  1204.   }
  1205. spread_stars()
  1206.   {
  1207.   int sta,sta2;
  1208.   for(sta=0;sta<STARNO;sta++)
  1209.     {
  1210.     star[sta].x=RANDOM(XMAX);
  1211.     star[sta].y=RANDOM(YMAX);
  1212.     for(sta2=0;sta2<sta;sta2++)
  1213.       if(star[sta2].x==star[sta].x && star[sta2].y==star[sta].y)
  1214.         {
  1215.         sta--;
  1216.         break;
  1217.         }
  1218.     }
  1219.   }
  1220. spread_players()
  1221.   {
  1222.   int i,j,k,l;
  1223.   for(i=0;i<PLAYERNO;i++)
  1224.     {
  1225.     task[i][0].headed=-1;
  1226.     for(l=0;l<100 && task[i][0].headed==-1;l++)
  1227.       {
  1228.       j=RANDOM(STARNO);
  1229.       if(distance(j,nearstar(j))>4) continue;
  1230.       for(k=0;k<i;k++) if(task[k][0].headed==j || distance(task[k][0].headed,j)<8) break;
  1231.       if(k==i) task[i][0].headed=j;
  1232.       }
  1233.     if(l==100) return(1);
  1234.     }
  1235.   return(0);
  1236.   }
  1237. update(sta)
  1238. int sta;
  1239.   {
  1240.   int p,pla,pla2,tas,ruler,totsize,totpop,totind;
  1241.   ruler=controlstar(sta);
  1242.   totsize=0;
  1243.   totpop=0;
  1244.   totind=0;
  1245.   for(p=0;p<PLANETNO;p++)
  1246.     {
  1247.     totsize+=star[sta].planet[p].size;
  1248.     totpop+=star[sta].planet[p].population;
  1249.     totind+=star[sta].planet[p].industry;
  1250.     }
  1251.   for(pla=0;pla<PLAYERNO;pla++)
  1252.     {
  1253.     if(!knowstar(pla,sta)) continue;
  1254.     CommData[pla].star[sta].ruler=ruler;
  1255.     CommData[pla].star[sta].totsize=totsize;
  1256.     CommData[pla].star[sta].totpop=totpop;
  1257.     CommData[pla].star[sta].totind=totind;
  1258.     CommData[pla].star[sta].danger=danger(pla,sta);
  1259.     CommData[pla].star[sta].when=general.time;
  1260.     }
  1261.   }
  1262. danger(pla,sta)
  1263. int pla;
  1264. int sta;
  1265.   {
  1266.   int pl,danger;
  1267.   for(pl=0;pl<PLAYERNO;pl++)
  1268.     if(pl!=pla)
  1269.       switch(general.relation[pl][pla])
  1270.         {
  1271.         case PEACE:danger += fi_pres(pl,sta);
  1272.                    break;
  1273.         case WAR  :danger += fi_pres(pl,sta)*2;
  1274.                    break;
  1275.         case ALLIANCE:danger += fi_pres(pl,sta)/2;
  1276.                    break;
  1277.         }
  1278.   return(danger);
  1279.   }
  1280. fi_pres(pla,sta)
  1281. int pla;
  1282. int sta;
  1283.   {
  1284.   int pres,tas;
  1285.   pres=0;
  1286.   for(tas=0;tas<TASKNO;tas++) if(ATSTAR(pla,tas,sta)) pres+=fi_strength(pla,tas);
  1287.   return(pres);
  1288.   }
  1289. fi_strength(pla,tas)
  1290. int pla;
  1291. int tas;
  1292.   {
  1293.   int shi,str;
  1294.   str=0;
  1295.   for(shi=0;shi<SHIPNO;shi++) str+=task[pla][tas].ship_free[shi]*fi_value(shi);
  1296.   return(str);
  1297.   }
  1298. fi_value(shi)
  1299. int shi;
  1300.   {
  1301.   if(ship[shi].attack*ship[shi].attackno==0) return(0);
  1302.   return(ship[shi].attack*ship[shi].attackno+ship[shi].shields*ship[shi].shields/5);
  1303.   }
  1304. #include "klingon.c"
  1305. #include "berserker.c"
  1306. #include "alien.c"
  1307. #include "romulan.c"
  1308.